var flag = true; //标记位

function FocusItem(obj) {
        $(obj).next('span').html('').remove('error');
}
function CheckItem(obj) {
    var msgBox =$(obj).next('span');
    switch ($(obj).attr('name')){
        case "username":
            if (obj.value == ""){
                msgBox.html('用户名不能为空');
                msgBox.addClass('error');
                flag = false;
            }else {
                msgBox.html().removeClass('error');
                flag = true;
            }
            break;
        case "pass":
            if (obj.value == ""){
                msgBox.html('密码不能为空');
                msgBox.addClass('error');
                flag = false;
            }else { flag = true;}
            break;
    }
}

function checkForm(frm) {
    var els = frm.getElementsByTagName('input');
    //有onblur属性的才需要验证
    for (var i = 0;i<els.length;i++){
        if (els[i]!=null){
            if (els[i].getAttribute("onblur")){
                CheckItem(els[i]);
            }
        }
    }
    return flag;
}